class Documents::ArticlesController < Documents::BaseController

  def index
    @search = Article.search(params[:search]) # TODO remove tabs, spaces...
    @articles = @search.page(params[:page])
  end

  def show
    @comments = @article.document.comments
  end

  def new
    @article = Article.new
  end

  def create
    @article = Article.new(params[:article])
    @article.document.user = current_user

    if @article.save
      flash[:notice] = t('articles.create.success')
      redirect_to :action => :index
    else
      render :action => :new
    end
  end

  def update
    if @article.update_attributes(params[:article])
      flash[:notice] = t('articles.update.success')
      redirect_to :action => :index
    else
      render :action => :edit
    end
  end
end
